Learn T-SQL Commands with Samples
Skip Navigation Links
Skip Navigation Links.
Expand DatabaseDatabase
Collapse TableTable
Expand ViewView
Expand Stored ProcedureStored Procedure
Expand Data FilteringData Filtering
Expand Data GroupingData Grouping
Expand JoinsJoins
Expand TriggerTrigger
Expand CursorCursor
Expand OperatorsOperators
Expand ConstraintsConstraints
Expand FunctionsFunctions
Expand Conditional ProcessingConditional Processing
Expand LoopingLooping
Expand Error HandlingError Handling
Expand v.IMP Queriesv.IMP Queries
Expand XMLXML
Expand Query PerformanceQuery Performance
Expand QueriesQueries
Expand NormalizationNormalization
Expand CreateCreate
     

Alter Table

 
      
---- Create Table
CREATE TABLE dbo.myTable ( ID int NOT NULL, Name char(23) NULL, City char(30) NULL ) GO
---- Alter Table (How to add New Columns; Drop and Alter existing Columns)
ALTER TABLE dbo.myTable
---- Add a new column to the table
ADD DOB datetime NULL,
---- Drop Existing Column
DROP COLUMN City,
---- Alter Existing Column
ALTER COLUMN Name char(30),
---- Add a new PRIMARY KEY CONSTRAINT to the table
ADD CONSTRAINT PK_myTable PRIMARY KEY (ID)